package com.mspbots.ticketai;

import com.mspbots.ticketai.graderule.GradeRuleInterceptor;
import com.mspbots.ticketai.model.Ticket;
import com.mspbots.ticketai.model.TicketRule;

/**
 * com.mspbots.core.ticketai.service.GradeRuleInterceptorRegistration
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/8/20
 */
public class GradeRuleInterceptorRegistration {

    private final GradeRuleInterceptor interceptor;
    private final String name;

    private int order = 0;

    public GradeRuleInterceptorRegistration(GradeRuleInterceptor interceptor, String interceptorName) {
        this.interceptor = interceptor;
        this.name = interceptorName;
    }


    /**
     * Specify an rule position to be used. Default is 0.
     */
    public GradeRuleInterceptorRegistration prepare(TicketRule params) {
        this.interceptor.prepare(params);
        return this;
    }


    /**
     * @return
     */
    public GradeRuleInterceptorRegistration process(Ticket ticket) {
        this.interceptor.process(ticket);
        return this;
    }

    /**
     * Specify an order position to be used. Default is 0.
     *
     * @since 4.3.23
     */
    public GradeRuleInterceptorRegistration order(int order) {
        this.order = order;
        return this;
    }

    /**
     * Return the order position to be used.
     */
    protected int getOrder() {
        return this.order;
    }

    public String getName() {
        return this.name;
    }

    public GradeRuleInterceptor getInterceptor() {
        return this.interceptor;
    }
}
